// phong shading, per-pixel
// 光照计算在像素着色器实现，定点着色器输出p和n

#version 450 core

// 最大支持的additional light数量
const uint ADDITIONAL_LIGHT_MAX_COUNT = 256;

layout(location = 0) in vec3 positionOS;
layout(location = 1) in vec2 uv;
layout(location = 2) in vec3 normalOS;

uniform mat4 objectToWorldMatrix;
uniform mat4 worldToObjectMatrix;
uniform mat4 vpMatrix;

flat out Varyings
{
    vec3 positionWS;
    vec3 normalWS;
    vec2 uv;
} outputs;

void main()
{
    outputs.positionWS = (objectToWorldMatrix * vec4(positionOS, 1.0)).xyz;
    // n: n_w = transpose(inverse(objectToWorld)) * n_o = transpose(worldToObject) * n_o = n_o * worldToObject
    outputs.normalWS = normalize(normalOS * mat3(worldToObjectMatrix));
    outputs.uv = uv;

    gl_Position = vpMatrix * vec4(outputs.positionWS, 1.0);
}
